<template>
    <div class="pt-[30px] pb-[20px] bg-white">
        <el-tabs v-model="activeStep" class="demo-tabs">
            <el-tab-pane label="基本信息" :name="0">
                <div>
                    <!-- 基本信息 -->
                    <div class="bg-white ">
                        <BaseHead>基本信息</BaseHead>
                        <div class="p-[10px]">
                            <el-descriptions title="" :column="2" border label-width="140">
                                <el-descriptions-item label-class-name="gdlable" label="专利名称">{{
            ruleForm.name
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="所属单位">
                                    <Feedback :id="ruleForm.unitId" :list="zcgsdwList"
                                        :mapping="['codeColumn', 'valueColumn']">
                                    </Feedback>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利类型">
                                    <Feedback :id="ruleForm.typeId" :list="zllxList">
                                    </Feedback>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利状态">
                                    <Feedback :id="ruleForm.stateId" :list="zlztList">
                                    </Feedback>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="申请号">{{
            ruleForm.applyCode
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="申请日">{{
                ruleForm.applyDate
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="公开号"
                                    v-if="ruleForm.stateId == '2' || ruleForm.stateId == '3'">{{
            ruleForm.openCode
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="公开日"
                                    v-if="ruleForm.stateId == '2' || ruleForm.stateId == '3'">{{
            ruleForm.openDate
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="授权公告号"
                                    v-if="ruleForm.stateId == '3'">{{
            ruleForm.authorizeCode
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="授权公告日"
                                    v-if="ruleForm.stateId == '3'">{{
            ruleForm.authorizeDate
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="申请人">{{
                ruleForm.applyInfo
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利权人"
                                    v-if="ruleForm.stateId == '3'">{{
            ruleForm.patentee
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利权状态"
                                    v-if="ruleForm.stateId == '3'">{{
            formatinvalidFlag(ruleForm.invalidFlag)
        }}
                                </el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </div>
                    <!-- 详细信息 -->
                    <div class="bg-white mt-[10px]">
                        <BaseHead>详细信息</BaseHead>
                        <div class="p-[10px]">
                            <el-descriptions title="" :column="2" border label-width="140">
                                <el-descriptions-item label-class-name="gdlable" label="合作类型">
                                    <Feedback :id="ruleForm.cooperationType" :list="hzlxList">
                                    </Feedback>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="联合申请知识产权协议书附件"
                                    v-if="ruleForm.cooperationType == '2'">
                                    <div v-for="item in ruleForm.joinFileList" :key="item.id">{{
            item.fileName }}<el-link type="primary" style="margin-left: 8px;"
                                            @click="downloadMet(item.id)">下载</el-link>
                                    </div>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="学校署名">{{
            ruleForm.schoolSign == 0 ? '第一单位' : '非第一单位'
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="是否职务专利">{{
                ruleForm.isDuty == 0 ? '否' : '是'
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利范围">
                                    <Feedback :id="ruleForm.scopeId" :list="zlfwList">
                                    </Feedback>
                                </el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="国家地区"
                                    v-if="ruleForm.scopeId == 2">{{
            ruleForm.region
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="是否代理">{{
                ruleForm.isAgency == 1 ? '是' : "否"
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="是否PCT专利">{{
                ruleForm.isPct == 1 ? '是' : "否"
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="IPC主分类号">{{
                ruleForm.patentIpc
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable"
                                    label="奖励证书">奖励证书</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="专利证书附件">
                                    <div v-for="item in ruleForm.crednetialFileList" :key="item.id">{{
            item.fileName }}<el-link type="primary" style="margin-left: 8px;"
                                            @click="downloadMet(item.id)">下载</el-link>
                                    </div>
                                </el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </div>
                    <!-- 代理信息 -->
                    <div class="bg-white mt-[10px]" v-if="ruleForm.isAgency == '1'">
                        <BaseHead>代理信息</BaseHead>
                        <div class="p-[10px]">
                            <el-descriptions title="" :column="2" border label-width="140">
                                <el-descriptions-item label-class-name="gdlable" label="代理公司">{{
            ruleForm.agencyName
        }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="通讯发明人">{{
                ruleForm.txAuthor
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="通讯发明人电话">{{
                ruleForm.txAuthorTel
            }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="附件">
                                    <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                                        }}<el-link type="primary" style="margin-left: 8px;"
                                            @click="downloadMet(item.id)">下载</el-link>
                                    </div>
                                </el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </div>
                    <!-- PCT信息 -->
                    <div class="bg-white mt-[10px]" v-if="ruleForm.isPct == '1'">
                        <BaseHead>PCT信息</BaseHead>
                        <div class="p-[10px]">
                            <el-descriptions title="" :column="2" border label-width="140">
                                <el-descriptions-item label-class-name="gdlable" label="PCT专利名称">{{
                                    ruleForm.pctName
                                    }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="PCT专利申请号">{{
                                    ruleForm.pctCode
                                    }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="PCT专利申请日期">{{
                                    dateFormatter3(ruleForm.pctDate)
                                    }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="PCT专利优先权日">{{
                                    ruleForm.priorityDate
                                    }}</el-descriptions-item>
                                <el-descriptions-item label-class-name="gdlable" label="进入国家">{{
                                    ruleForm.enterCountry
                                    }}</el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </div>
                    <!-- 发明（设计）人 -->
                    <div class="bg-white mt-[10px]">
                        <BaseHead>发明（设计）人 </BaseHead>
                        <div class="p-[10px]">
                            <el-table :data="tableData" border style="width: 100%">
                                <el-table-column align="center" type="index" label="署名顺序" width="80" />
                                <el-table-column align="center" prop="authorType" label="发明人类型">
                                    <template #default="scope">
                                        {{
                                        scope.row.authorType=='1'?'教师': scope.row.authorType=='2'?'学生':'校外'
                                        }}</template>
                                </el-table-column>
                                <el-table-column align="center" prop="authorName" label="发明人姓名">

                                </el-table-column>
                                <el-table-column align="center" prop="eduLevelId" label="学历">
                                    <template #default="scope">
                                        <Feedback :id="scope.row.eduLevelId" :list="xlList"></Feedback>
                                    </template>
                                </el-table-column>
                                <el-table-column align="center" prop="address" label="学位">
                                    <template #default="scope">
                                        <Feedback :id="scope.row.eduDegreeId" :list="xwList"></Feedback>
                                    </template>
                                </el-table-column>
                                <el-table-column align="center" prop="authorUnit" label="工作单位">
                                </el-table-column>
                                <el-table-column align="center" prop="titleId" label="职称">
                                    <template #default="scope">
                                        <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                            :render-after-expand="false" disabled />
                                    </template>
                                </el-table-column>
                                <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="依托项目" :name="1">
                <supportProjectView :productId="id"></supportProjectView>
            </el-tab-pane>
        </el-tabs>

    </div>
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import supportProjectView from "@/views/achievement/components/supportProjectView.vue"
import useCategoryStore from "@/store/modules/category";

const props = defineProps({
    id: String,
})
const ruleForm = reactive({
});
const tableData = reactive([
]);

const categoryStore = useCategoryStore();
const { xlList, zcgsdwList, zcList, xwList, zlztList, hzlxList, zlfwList, gjdqList, zllxList } = storeToRefs(categoryStore); // 解构状态
const { getxlList, getzcgsdwList, getzcList, getxwList, getzlztList, gethzlxList, getzlfwList, getgjdqList, getzllxList } = categoryStore; // 解构方法
const formatinvalidFlag = (cellValue) => {
    let invalidFlagArr = [
        {
            code: 'ineffective',
            name: '未生效'
        },
        {
            code: 'yes',
            name: '有效'
        },
        {
            code: 'rollout',
            name: '已转出'
        },
        {
            code: 'no',
            name: '无效'
        }
    ]
    return invalidFlagArr.find(item => item.code == cellValue) ? invalidFlagArr.find(item => item.code == cellValue).name : ''


}



const getRuleForm = (i) => {
    if (!xlList.value.length) {
        getxlList()
    }
    if (!zcgsdwList.value.length) {
        getzcgsdwList()
    }
    if (!zcList.value.length) {
        getzcList()
    }
    if (!xwList.value.length) {
        getxwList()
    }
    if (!zlztList.value.length) {
        getzlztList()
    }
    if (!hzlxList.value.length) {
        gethzlxList()
    }
    if (!zlfwList.value.length) {
        getzlfwList()
    }
    if (!gjdqList.value.length) {
        getgjdqList()
    }
    if (!zllxList.value.length) {
        getzllxList()
    }

    if (i.authorList && i.authorList.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.authorList); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
}
const activeStep = ref(0)

const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}

defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
